﻿using System;
using System.Collections.Generic;
using System.Linq;

internal class GendarmeXMLTemplateTags
{
    public bool AutomaticallyWhitelistAttributes = true;
    public List<string> BlackListAssemblies = new List<string>();
    public List<string> BlackListFiles = new List<string>();
    public bool IncludePrimitiveTypes = true;
    public List<string> LimitToNamespaces = new List<string>();
    public List<string> WhiteListAssemblies = new List<string>();
    public List<string> WhiteListFiles = new List<string>();
    public List<string> WhiteListTypes = new List<string>();

    private string AggregateIntoString(IEnumerable<string> list)
    {
        return Enumerable.Aggregate<string>(list.DefaultIfEmpty<string>(), new Func<string, string, string>(GendarmeXMLTemplateTags.ToCommaSeparatedString));
    }

    private static string ToCommaSeparatedString(string agg, string s)
    {
        return (agg + "," + s);
    }

    public Dictionary<string, string> ToTagsDictionary()
    {
        Dictionary<string, string> dictionary = new Dictionary<string, string>();
        dictionary.Add("IncludePrimitiveTypes", !this.IncludePrimitiveTypes ? "0" : "1");
        dictionary.Add("AutomaticallyWhitelistAttributes", !this.AutomaticallyWhitelistAttributes ? "0" : "1");
        dictionary.Add("LimitToNamespaces", this.AggregateIntoString(this.LimitToNamespaces));
        dictionary.Add("WhiteListTypes", this.AggregateIntoString(this.WhiteListTypes));
        dictionary.Add("WhiteListFiles", this.AggregateIntoString(this.WhiteListFiles));
        dictionary.Add("BlackListFiles", this.AggregateIntoString(this.BlackListFiles));
        dictionary.Add("WhiteListAssemblies", this.AggregateIntoString(this.WhiteListAssemblies));
        dictionary.Add("BlackListAssemblies", this.AggregateIntoString(this.BlackListAssemblies));
        return dictionary;
    }
}

